window.onload = function () {
    let homeHero = document.querySelector(".home-hero");
    let cartMini = document.querySelector(".cart-mini");
    let cartMenu = document.querySelector(".cart-menu");
    let navItems = document.querySelectorAll(".nav-item");
    let headerNavMenus = document.querySelectorAll(".header-nav-menu");
    let preMenu = headerNavMenus[0];
    // let categoryList = document.querySelector(".site-category-list");
    let categoryItems = document.querySelectorAll(".category-item");
    let categoryChildren = document.querySelectorAll(".children");
    let preChild = categoryChildren[0];
    let timer = null;
    let carMenuTimer = null;
    let categoryTimer = null;
    let typeAll = document.querySelector(".nav-category");
    let siteCategory = document.querySelector(".site-category");
    //购物车
    cartMini.onmouseenter =()=>{
        clearTimeout(carMenuTimer);
        cartMenu.style.display = "block";
    };
    cartMini.onmouseleave = ()=>{
        carMenuTimer = setTimeout(()=>{
            cartMenu.style.display = "none";
        },400);
    };
    cartMenu.onmouseenter = function(){
        clearTimeout(carMenuTimer);
        this.style.display = "block";
    };
    cartMenu.onmouseleave = function () {
        this.style.display = "none";
    };
    //头部导航hover菜单
    for(var i=0;i<8;i++){
        navItems[i].index = i;
        headerNavMenus[i].index = i;
        navItems[i].onmouseenter = function () {
            preMenu.style.display = "none";
            clearTimeout(timer);
            headerNavMenus[this.index].style.display = "block";
            preMenu = headerNavMenus[this.index];
        };
        navItems[i].onmouseleave = function () {
            index1 = this.index;
            timer = setTimeout(function () {
                headerNavMenus[index1].style.display = 'none';
            },400);
        };
        headerNavMenus[i].onmouseenter = function () {
            clearTimeout(timer);
            this.style.display = 'block';
        };
        headerNavMenus[i].onmouseleave = function () {
            index2 = this.index;
            timer = setTimeout(function () {
                headerNavMenus[index2].style.display = 'none';
            },400);
        }
    }
    //竖导航栏右侧hover商品栏
    for(var i=0;i<categoryItems.length;i++){
        categoryItems[i].index = i;
        categoryChildren[i].index = i;
        categoryItems[i].onmouseenter = function () {
            preChild.style.display = "none";
            clearTimeout(categoryTimer);
            categoryChildren[this.index].style.display = "block";
            preMenu = headerNavMenus[this.index];
        };
        categoryItems[i].onmouseleave = function () {
            index1 = this.index;
            categoryChildren[index1].style.display = 'none';
        };
    }

    typeAll.onmouseenter = function () {
        siteCategory.style.display = "block";
    }
    typeAll.onmouseleave = function () {
        siteCategory.style.display = "none";
    }
};